package com.thuan.pojo;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity
@Table(name = "League")
public class League implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4801905469968924467L;
	
	@Id @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "league_id")
    private int leagueId;
	
	@Column(name = "name")
	private String name;
	
	@ManyToOne
    @JoinColumn(name="reward_id", 
                insertable=true, updatable=true, 
                nullable=false)
	private Reward reward;
	
	@Column(name = "start_date")
    @Temporal(TemporalType.DATE)
    private Date startDate;

	@Column(name = "end_date")
    @Temporal(TemporalType.DATE)
    private Date endDate;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "league")
	private Set<Competition> competitionsForLeague = new HashSet<Competition>();
    
	@ManyToMany(mappedBy="leagues")
    private Set<UserAccount> players = new HashSet<UserAccount>();
	
	public League() {}
	
	public League(int id) {
		this.leagueId = id;
	}
	
	public League(String name, Reward reward, Date startDate, Date endDate) {
		this.name = name;
		this.reward = reward;
		this.startDate = startDate;
		this.endDate = endDate;
	}

	public int getLeagueId() {
		return leagueId;
	}

	public void setLeagueId(int leagueId) {
		this.leagueId = leagueId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Reward getReward() {
		return reward;
	}

	public void setReward(Reward reward) {
		this.reward = reward;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Set<Competition> getCompetitionsForLeague() {
		return competitionsForLeague;
	}

	public void setCompetitionsForLeague(Set<Competition> competitionsForLeague) {
		this.competitionsForLeague = competitionsForLeague;
	}
	
	
}
